<?php
/**
 * Created by PhpStorm.
 * User: 魏爷
 * Date: 2016/4/22
 * Time: 12:55
 */

namespace Admin\Controller;


class ReadManageController extends  BaseController
{
    /**
     * 读者类型管理
     **/
    public function readTypeManage(){
        $getReadTypeInfo=D('ReadManage')->getReadTypeInfo();
        $this->assign('_getReadTypeInfo',$getReadTypeInfo);
        $this->display('ReadManage/readTypeManage');
    }
    /**
     * 读者认证管理
     **/
    public function readRealManage(){
        $u_name=I('u_name');
        $u_email=I('u_email');
        $u_type_name=I('u_type_name');
        $getUserAndType=D('User')->getUserStatusInfo($u_name,$u_email,$u_type_name);
        $getAllReadType=D('ReadManage')->getAllReadType();
        $this->assign('_getAllReadType',$getAllReadType);
        $this->assign('_getUserAndType',$getUserAndType);
        $this->display('ReadManage/readRealManage');
    }
    /**
     * 读者档案管理
     **/
    public function readRecordManage(){
        $u_name=I('u_name');
        $u_email=I('u_email');
        $u_type_name=I('u_type_name');
        $getUserAndType=D('User')->getUserAndType($u_name,$u_email,$u_type_name);
        $getAllReadType=D('ReadManage')->getAllReadType();
        $this->assign('_getAllReadType',$getAllReadType);
        $this->assign('_getUserAndType',$getUserAndType);
        $this->display('ReadManage/readRecordManage');
    }

    /**
     * 读者档案修改跳转
    **/
    public function readRecordSave(){
        $u_id=I('id');
        session('u_info_id',$u_id);
        $getAllReadType=D('ReadManage')->getAllReadType();
        $getUserInfo=D('User')->getUserInfo($u_id);
        $this->assign('_getAllReadType',$getAllReadType);
        $this->assign('_getUserInfo',$getUserInfo);
        $this->display('ReadManage/readRecordSaveManage');
    }
    /**
     * 读者档案修改后跳转
    **/
    public function readRecordSaved(){
        $u_id=getUserInfoId();
        $getAllReadType=D('ReadManage')->getAllReadType();
        $getUserInfo=D('User')->getUserInfo($u_id);
        $this->assign('_getAllReadType',$getAllReadType);
        $this->assign('_getUserInfo',$getUserInfo);
        $this->display('ReadManage/readRecordSaveManage');
    }


    /**读者类型添加**/
    public function readTypeAdd(){
        $u_type_name=I('u_type_name');
        $u_book_borrow=I('u_book_borrow');
        $a_id=getAdminId();
        if(empty($u_type_name)||empty($u_book_borrow)||empty($a_id)){
            $this->error('添加失败',null,true);
        }
        $type_name=D('ReadManage')->getReadTypeName($u_type_name);
        if($type_name==false){
            $this->error('添加失败',null,true);
        }
        $res=D('ReadManage')->readTypeAdd($a_id,$u_type_name,$u_book_borrow);
        if($res==false){
            $this->error('添加失败',null,true);
        }else{
            $this->success('添加成功',null,true);
        }
    }
    /**读者类型禁用**/
    public function readTypeDis(){
        $u_type_id=I('u_type_id');
        $res=D('ReadManage')->readTypeDis($u_type_id);
        if($res==false){
            $this->error('禁用失败',null,true);
        }else{
            $this->success('禁用成功',null,true);
        }
    }
    /**读者类型恢复**/
    public function readTypeRec(){
        $u_type_id=I('u_type_id');
        $res=D('ReadManage')->readTypeRec($u_type_id);
        if($res==false){
            $this->error('恢复失败',null,true);
        }else{
            $this->success('恢复成功',null,true);
        }
    }

    /**读者类型删除**/
    public function readTypeDel(){
        $u_type_id=I('u_type_id');
        $res=D('ReadManage')->readTypeDel($u_type_id);
        if($res==false){
            $this->error('删除失败',null,true);
        }else{
            $this->success('删除成功',null,true);
        }
    }

    /**读者类型检索查询**/
    public function readTypeSerach(){
        $u_type_name=I('u_type_name');
        $u_type_status=I('u_type_status');
        $getReadTypeInfo=D('ReadManage')->getReadTypeInfo($u_type_name,$u_type_status);
        $this->assign('_getReadTypeInfo',$getReadTypeInfo);
        $this->display('ReadManage/readTypeManage');
    }

    /**读者认证驳回**/
    public function readRealDel(){
        $u_id=I('u_id');
        $res=D('User')->readRealDel($u_id);
        if($res==false){
            $this->error('驳回失败',null,true);
        }else{
            $this->success('驳回成功',null,true);
        }
    }
    /**读者认证同意**/
    public function readRealRec(){
        $u_id=I('u_id');
        $res=D('User')->readRealRec($u_id);
        if($res==false){
            $this->error('同意失败',null,true);
        }else{
            $this->success('同意成功',null,true);
        }
    }

    /**读者信息添加**/
    public function readRecordAdd(){
        $u_name=I('u_name');
        $u_email=I('u_email');
        $u_pwd=I('u_pwd');
        $u_repwd=I('u_repwd');
        $u_sex=I('u_sex');
        $u_type_id=I('u_type_id');
        $u_tel=I('u_tel');
        if(empty($u_name)||empty($u_email)||empty($u_pwd)||empty($u_repwd)||empty($u_sex)||empty($u_type_id)||empty($u_tel)){
            $this->error('添加失败',null,true);
        }
        if($u_pwd!=$u_repwd){
            $this->error('添加失败',null,true);
        }
        $email=D('User')->getUserEmail($u_email);
        if($email==true){
            $this->error('邮箱存在',null,true);
        }
        $res=D('User')->readRecordAdd($u_name,$u_email,$u_pwd,$u_sex,$u_type_id,$u_tel);
        if($res==false){
            $this->error('添加失败',null,true);
        }else{
            $this->success('添加成功',null,true);
        }
    }

    /**读者档案删除**/
    public function readRecordDel(){
        $u_id=I('u_id');
        $res=D('User')->readRecordDel($u_id);
        if($res==false){
            $this->error('删除失败',null,true);
        }else{
            $this->success('删除成功',null,true);
        }
    }

    /**读者档案恢复**/
    public function readRecordRec(){
        $u_id=I('u_id');
        $res=D('User')->readRecordRec($u_id);
        if($res==false){
            $this->error('恢复失败',null,true);
        }else{
            $this->success('恢复成功',null,true);
        }
    }

    /**读者档案读者类型修改**/
    public function readRecordTypeSave(){
        $u_id=I('u_id');
        $u_type_id=I('u_type_id');
        $res=D('User')->readRecordTypeSave($u_id,$u_type_id);
        if($res==false){
            $this->error('修改失败',null,true);
        }else{
            $this->success('修改成功',null,true);
        }
    }

    /**读者信息修改**/
    public function readRecordInfoSave(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize=3145728 ;// 设置附件上传大小
        $upload->exts=array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = './';
        $upload->savePath ='./Public/Uploads/'; // 设置附件上传目录
        $upload->autoSub=false;
        $upload->saveName = array('uniqid','');
        $info   =   $upload->uploadOne($_FILES['u_pic']);
        if(empty($info)) {// 上传错误提示错误信息
            $u_id=getUserInfoId();
            $u_name=I('u_name');
            $u_tel=I('u_tel');
            $u_age=I('u_age');
            $u_address=I('u_address');
            $u_postcode=I('u_postcode');
            $u_sex=I('u_sex');
            if(empty($u_name)||empty($u_tel)){
                $this->error('标准信息不能为空',U('Admin/ReadManage/readRecordSaved'));
            }
            $res=D('User')->readRecordInfoSave($u_id,$u_name,$u_tel,$u_age,$u_address,$u_postcode,$u_sex);
            if($res==false){
                $this->error('修改失败',U('Admin/ReadManage/readRecordSaved'));
            }else{
                $this->success('修改成功',U('Admin/ReadManage/readRecordSaved'));
            }
        }else{
            $pictrueName=$info['savename'];
            $u_id=getUserInfoId();
            $u_name=I('u_name');
            $u_tel=I('u_tel');
            $u_age=I('u_age');
            $u_address=I('u_address');
            $u_postcode=I('u_postcode');
            $u_sex=I('u_sex');
            if(empty($u_name)||empty($u_tel)){
                $this->error('标准信息不能为空',U('Admin/ReadManage/readRecordSaved'));
            }
            $res=D('User')->readRecordInfoSave($u_id,$u_name,$u_tel,$u_age,$u_address,$u_postcode,$u_sex,$pictrueName);
            if($res==false){
                $this->error('修改失败',U('Admin/ReadManage/readRecordSaved'));
            }else{
                $this->success('修改成功',U('Admin/ReadManage/readRecordSaved'));
            }
        }
    }


}